//
//  HWApplyjiesuanViewController.m
//  HWPromoteProjectAPP
//
//  Created by 陈道斌 on 2020/2/17.
//  Copyright © 2020 陈道斌. All rights reserved.
//

#import "HWApplyjiesuanViewController.h"
#import "HWBillingDetailsViewController.h" // 结算
#import "HWApplyForSettlementViewController.h"


@interface HWApplyjiesuanViewController ()

@property(strong,nonatomic) UIView *navigationTopView;
@property(strong,nonatomic) UILabel *zhanghaoLabel;
//@property(strong,nonatomic) UILabel *qudaoLabel; //渠道ID
@property(strong,nonatomic) UIImageView *icoIamgeView; // 头像

@property(strong,nonatomic)UIView *kesuanjianView;
@property(strong,nonatomic)UITextField *manaTextField;

@property(strong,nonatomic)UIView *tishiView;


 


@end

@implementation HWApplyjiesuanViewController




- (void)viewWillAppear:(BOOL)animated  {
    
    [super viewWillAppear:animated];
//    self.navigationController.navigationBarHidden = NO;
    [self.navigationController setNavigationBarHidden:NO animated:animated];
    // 请求数据
    [self fasongwanglu];
    
    
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    [self setupNavigate];
    
    [self setupUI];
    
    // 设置属性
    [self setUpshuxing];
    
}





- (void)fasongwanglu {
    
    
    
    
        NSString *tStr = [NSString stringWithFormat:@"%ld",[WMUtil getTimeSp]];
         NSString *uid =  [HWLocallyStoredData getLoginUserID];
         NSString *signStr = [NSString stringWithFormat:@"%@%@%@",uid,tStr,@"adesxloksy13s98adv"];
         NSString  *signStrMd5  =   [WMUtil md5HexDigest:signStr];
           
        
        
        
          NSDictionary *parametes = @{      @"ios" : @"1",
                                       @"ct" : @"app",
                                        @"ac" : @"my",
                                        @"t" : tStr,
                                        @"uid":uid,
                                        @"sign" :signStrMd5
                                        };
        
        
            [HWWebUtils doGetWithParameters:parametes progress:nil success:^(id response) {
                  
                 

                  NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
                  if ([codeStr intValue] == 1) {
                 
                        NSLog(@"%@",response);
                  //       self.datadic = response[@"data"];
                      
                    //    self.dataMutableArr = [MyicoImageModel mj_objectArrayWithKeyValuesArray:response[@"data"][@"function"]];
                      
                     //  [self.icoimageView sd_setImageWithURL:[NSURL URLWithString:self.datadic[@"head"]] placeholderImage:nil];
                      
                 //     self.mingchenLabel.text = [NSString stringWithFormat:@"%@",self.datadic[@"username"]];
                      
                     //  self.keyongjingerLabel.text = [NSString stringWithFormat:@"%@",self.datadic[@"shareMoney"]];
                      
                      
                  //     self.cunchuStr = [NSString stringWithFormat:@"%@",self.datadic[@"shareMoney"]];
                      
                   //    self.yufujingeLabel.text = [NSString stringWithFormat:@"%@",self.datadic[@"yufu"]];
                  //     self.tuiguanjingerLabel.text = [NSString stringWithFormat:@"%@",self.datadic[@"money"]];
                      
                      NSString  *pay =  [NSString stringWithFormat:@"%@",response[@"pay"]];
                      
                      
                      
                      self.jisuanStr =    [NSString stringWithFormat:@"%@", response[@"data"][@"shareMoney"]];
                      
            
                    
                        self.manaTextField.placeholder = [NSString stringWithFormat:@"可结算金额: %@",self.jisuanStr];
                      
                      
                      
                      
                       
                  } else {
                      
                    [MBProgressHUD showError:response[@"message"]];
                                    
                
                      
                  }
                  
             
                  
              } failure:^(NSString *error) {
                 // [SVProgressHUD dismiss];
                  
                   [MBProgressHUD showSuccess:@"登录失败"];
                  [MBProgressHUD hideHUD];
                  
                  
              }];
        
    
    
    
    
    
    
    
    
    
    
    
}


- (void)setUpshuxing {
    
    self.manaTextField.placeholder = [NSString stringWithFormat:@"可结算金额: %@",self.jisuanStr];
    
    // @"可结算金额 600.32";
    
    
    self.zhanghaoLabel.text = [NSString stringWithFormat:@"%@",[HWLocallyStoredData getUsername]];
    //   self.qudaoLabel.text = [NSString stringWithFormat:@"%@",@"用户名"];
       [self.icoIamgeView  sd_setImageWithURL:[NSURL URLWithString:[HWLocallyStoredData getHead]] placeholderImage:nil];
       
    
    
    
    
}


- (void)setupNavigate  {
    
    self.navigationItem.title = @"申请结算";
    UIBarButtonItem *buttonItem =  [[UIBarButtonItem alloc]initWithTitle:@"结算明细" style:UIBarButtonItemStylePlain target:self action:@selector(rightBarButtonTap)];
    buttonItem.tintColor  = RGB(68, 68, 68);
    self.navigationItem.rightBarButtonItem = buttonItem;
    
    
    
}




// 设置UI
- (void)setupUI {
    
    
       self.view.backgroundColor =  beijingyanSe;
       self.navigationTopView  = [[UIView alloc]initWithFrame:CGRectMake(0, 0 , SCREEN_WIDTH, 60)];
       self.navigationTopView .backgroundColor = [UIColor whiteColor];
       [self.view addSubview:self.navigationTopView ];
      
    
         self.icoIamgeView = [[UIImageView alloc]initWithFrame:CGRectMake( 20, 12, 36, 36)];
         self.icoIamgeView.backgroundColor = [UIColor redColor];
         self.icoIamgeView.layer.cornerRadius = 12;
         self.icoIamgeView.layer.masksToBounds  = YES;
         [self.navigationTopView  addSubview:self.icoIamgeView];
    
    
       self.zhanghaoLabel  = [[UILabel alloc]initWithFrame:CGRectMake(self.icoIamgeView.right+10, 0, SCREEN_WIDTH-86, 60)];
       self.zhanghaoLabel.text = @"63527373";
       self.zhanghaoLabel.textAlignment =  NSTextAlignmentLeft;
       self.zhanghaoLabel.textColor = RGB(68, 68, 68);
       self.zhanghaoLabel.font = [UIFont systemFontOfSize:18];
       [self.navigationTopView  addSubview:self.zhanghaoLabel];
     
       
       [self addkesuanjianView];
    
    
}


// 添加金额UIiew
- (void)addkesuanjianView {
    
    self.kesuanjianView = [[UIView alloc]initWithFrame:CGRectMake(0, self.navigationTopView.bottom, SCREEN_WIDTH, 74)];
    self.kesuanjianView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview: self.kesuanjianView];
    
    
    UIView *fengexiaView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 1)];
    fengexiaView.backgroundColor = RGB(243, 242, 243);
    [  self.kesuanjianView  addSubview:fengexiaView ];
    
    
    
     UIImageView   *qinashuImage   = [[UIImageView alloc]initWithFrame:CGRectMake( 20, 25, 24 , 24)];
    // qinashuImage.backgroundColor = [UIColor redColor];
    qinashuImage.image = [UIImage imageNamed:@"￥_ico"];
     [ self.kesuanjianView  addSubview:qinashuImage];
    
    
    UIButton *wangjibutton = [UIButton buttonWithType:UIButtonTypeCustom];
    wangjibutton.frame = CGRectMake(SCREEN_WIDTH-40-20 ,22,40, 30);
    [wangjibutton setTitle:@"全部" forState:UIControlStateNormal];
    [wangjibutton setTitleColor:RGB(85, 89, 234) forState:UIControlStateNormal];
    wangjibutton.titleLabel.font = [UIFont systemFontOfSize:18];
    [wangjibutton addTarget:self action:@selector(quanbu) forControlEvents:UIControlEventTouchUpInside];
    [self.kesuanjianView addSubview:wangjibutton];
    

    
    
     UITextField *textfeild1 = [[UITextField alloc]initWithFrame:CGRectMake(qinashuImage.right+10, 20,210 , 34)];
     textfeild1.placeholder = @"可结算金额 600.32";
  //  textfeild1.secureTextEntry = YES;
    
    textfeild1.keyboardType = UIKeyboardTypeDecimalPad;
    textfeild1.textColor = RGB(68, 68, 68);
    textfeild1.font = [UIFont systemFontOfSize:14];
 //   textfeild1.borderStyle =UITextBorderStyleNone;
//    textfeild1.layer.borderWidth = 1;
//    textfeild1.layer.borderColor = RGB(230, 239, 233).CGColor;
//    textfeild1.layer.cornerRadius = 6;
//    textfeild1.layer.masksToBounds = YES;
     self.manaTextField = textfeild1;
     [self.kesuanjianView addSubview:textfeild1];
    
    
    self.tishiView = [[UIView alloc]initWithFrame:CGRectMake(0, self.kesuanjianView.bottom, SCREEN_WIDTH, 30 )];
    self.tishiView.backgroundColor = RGB(255, 250, 238);
    [self.view addSubview:self.tishiView];
    
    
    
       UILabel *tishizhanghaoLabel  = [[UILabel alloc]initWithFrame:CGRectMake(20, 0, SCREEN_WIDTH-30, 30)];
        tishizhanghaoLabel.text = @"提示：结算金额输入不能低于10元";
        tishizhanghaoLabel.textAlignment =  NSTextAlignmentLeft;
        tishizhanghaoLabel.textColor = RGB(255, 182, 10);
        tishizhanghaoLabel.font = [UIFont systemFontOfSize:12];
       [self.tishiView addSubview:tishizhanghaoLabel];
    
    
    
      
       
    
         UIButton *submitbutton = [UIButton buttonWithType:UIButtonTypeCustom];
         submitbutton.frame = CGRectMake(20 , self.tishiView.bottom+95,SCREEN_WIDTH-40,44);
         
         [submitbutton setTitle:@"提交" forState:UIControlStateNormal];
         [submitbutton setTitleColor:RGB(255, 255, 255) forState:UIControlStateNormal];
         submitbutton.titleLabel.font = [UIFont systemFontOfSize:16];
         [submitbutton addTarget:self action:@selector(submit) forControlEvents:UIControlEventTouchUpInside];
          submitbutton.backgroundColor = RGB(85, 89, 234);
    
    
         [self.view addSubview:submitbutton];
    
   
    
    
    
    
    
    
    
    
    
    
    
}



//结算明细按钮
- (void)rightBarButtonTap {
    
    HWBillingDetailsViewController *billing = [[HWBillingDetailsViewController alloc]init];
    [self.navigationController pushViewController:billing animated:YES];
    
    
    
    
    
}


//点击确定按钮

- (void)quanbu {
    
    NSLog(@"确定按钮");
      self.manaTextField.text = [NSString stringWithFormat:@"%@",self.jisuanStr];
    
    
}

// 提交按钮
- (void)submit {
  
    
    NSString *jingStr = [NSString stringWithFormat:@"%@",self.manaTextField.text];

    CGFloat  jingEF = [jingStr doubleValue];
    if (!(jingEF > 10 )) {
        
        NSLog(@"jcj");
        [MBProgressHUD showError:@"提现金额最低10元"];
        
        return;
        
        
        
    }else if (jingEF > [self.jisuanStr floatValue] ){
        
       [MBProgressHUD showError:@"提现金额因该小于结算金额"];
        return;
        
        
    }
    
    
    
    else {
         NSLog(@"dgggg"); 
    }
    
    
    
    
           NSString *tStr = [NSString stringWithFormat:@"%ld",[WMUtil getTimeSp]];
            NSString *uid =  [HWLocallyStoredData getLoginUserID];
            NSString *signStr = [NSString stringWithFormat:@"%@%@%@%@",uid,jingStr,tStr,@"adesxloksy13s98adv"];
            NSString  *signStrMd5  =   [WMUtil md5HexDigest:signStr];
              
           
           
           
             NSDictionary *parametes = @{      @"ios" : @"1",
                                          @"ct" : @"app",
                                           @"ac" : @"jiesuan",
                                           @"t" : tStr,
                                           @"uid":uid,
                                           @"money":jingStr,
                                           @"sign" :signStrMd5
                                           };
           
           
               [HWWebUtils doGetWithParameters:parametes progress:nil success:^(id response) {
                     
                    

                     NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
                     if ([codeStr intValue] == 1) {
                    
                           NSLog(@"%@",response);
                      
                            NSLog(@"成功");
                         
                         HWApplyForSettlementViewController *ApplyForSettle = [[HWApplyForSettlementViewController alloc]init];
                         [self.navigationController pushViewController:ApplyForSettle animated:YES];
                         
                          
                    
                         
                   
                   
                         
                          
                     } else {
                         
                       [MBProgressHUD showError:response[@"message"]];
                                       
                   
                         
                     }
                     
                
                     
                 } failure:^(NSString *error) {
                    // [SVProgressHUD dismiss];
                     
                      [MBProgressHUD showSuccess:@"登录失败"];
                     [MBProgressHUD hideHUD];
                     
                     
                 }];

    
    
    
    
    
    
    
    
}





@end
